<?php
class KhoalanAdmin extends CI_Controller
{
	function danhsachkl()
	{
		$data = array( 
			'dskl'=>$this->mkhoalan->danhsachkhoalan(),
			'page'=>'danhsachkhoalan'
		);
		$this->load->view('admin/templateadmin', $data);
	}
	
	function xoakhoalan($makl)
	{
		$this->mkhoalan->xoakl($makl);
		redirect('admin/khoalanadmin/danhsachkl');	
	}
	
	function capnhatkhoalan($makl)
	{
		$data = array('ttkl'=>$this->mkhoalan->thongtinkhoalan($makl),'page'=>'capnhatkhoalan');
		$this->load->view('admin/templateadmin',$data);
	}
	
	function thongtinkl($makl)
	{
		$data = array(
			'page'=>'thongtinkhoalan',
			'ttkl'=>$this->mkhoalan->thongtinkhoalan($makl)
		);
		$this->load->view('admin/templateadmin', $data);
	}
	
	function xulycapnhat()
	{
		$makl = $this->input->post('makl');
		$tenkl = $this->input->post('tenkl');
		$ngaybatdau = $this->input->post('ngaybatdau');
		$ngayketthuc = $this->input->post('ngayketthuc');
		$gia = $this->input->post('gia');
		$mota = $this->input->post('mota');
		$hienthi = $this->input->post('hienthi')=='true' ? 'true' : 'false';
		
		//cap nhat hinh anh
		$config['upload_path'] = './asset/upload/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size']	= '1024';
		$config['encrypt_name']	= true;
		$this->load->library('upload', $config);
		
		if($this->upload->do_upload('hinh'))
		{
			$df = array('upload_data' => $this->upload->data());
			$hinh = $df['upload_data']['file_name'];
		}
		if ($hinh == '')
			$hinh = $this->input->post('oldhinh');
			
		$this->mkhoalan->capnhatkl($makl, $tenkl, $ngaybatdau, $ngayketthuc, $gia, $mota, $hienthi, $madm);
		redirect('admin/khoalanadmin/danhsachkl');
	}
	
	function themkhoalan()
	{
		$data = array(
			'page'=>'themkhoalan'
			
		);
		$this->load->view('admin/templateadmin', $data);
	}
	
	function xulythem()
	{
		$tenkl = $this->input->post('tenkl');
		$magv = $this->input->post('magv');
		$ngaybatdau = $this->input->post('ngaybatdau');
		$ngayketthuc = $this->input->post('ngayketthuc');
		$gia = $this->input->post('gia');
		$mota = $this->input->post('mota');
		
		// Thuc hien upload hinh anh
		$config['upload_path'] = './asset/upload/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size']	= '1024';
		$config['encrypt_name']	= true;
		$this->load->library('upload', $config);
		$hinh = '';
		if($this->upload->do_upload('hinh'))
		{
			$df = array('upload_data' => $this->upload->data());
			$hinh = $df['upload_data']['file_name'];
		}
		
		$hienthi = $this->input->post('hienthi')=='true' ? 'true' : 'false';
		$madm = $this->input->post('madm');
		$this->mkhoalan->themkl($tenkl, $magv, $ngaybatdau, $ngayketthuc, $gia, $mota, $hinh, $hienthi, $madm);
		redirect('admin/khoalanAdmin/danhsachkl');		
	}
}

?>